File Manager

Keeps track of every file in the system
Provides an abstracted view of files to the user (logical file system) and maps this on to the real organisation of data on disk (physical file system)

File manager performs various tasks for the OS:

Disk Drives

HDD SSD
- Mechanical device with moving parts
- Slower access speeds (disk needs to spin, head needs to move)
- Shorter lifespan from wear and tear
- Uses more power (around 8 watts)
- Risk from vibration and damage in transit
- No moving parts
- Faster access speeds (electronic circuits via system bus)
- Longer lifespan
- More energy efficient (around 2 watts)
- Impervious to knocks and vibrations
- Higher Capacity
- Cheaper
- Less Capacity
- More Expensive

Disk Blocks

Disks are based around the idea of blocks

Each physical disk can be divided into separate partitions

Free List & Metadata

Parts of each disk are reserved to store data about the disk and the files on it

Some disadvantages:

File Systems and System Calls

Every file system has four parts

System calls include fopen, fclose, fread, fwrite, fseek, fflush

User programs see the logical view of the file system via these system calls

Logical and Physical Views

Operating Systems provide conveniences to make life easier for us

However, the OS doesn't follow nor need these human conveniences

Inodes and Metadata

There must be some way to map the logical view on to physical locations on disk

Actual storage space = Capacity - (Housekeeping data, Free list, Inode table)

File Allocation and Access

There are several ways to allocate files to blocks on a disk

Sequential file access

Contiguous Allocation

Each file is allocated across contiguous blocks on the disk (eg. next to each other)
![[Pasted image 20250519014631.png]]

The inode stores the start block number and number of blocks

Advantages
Disadvantages

Linked Allocation

Each block contains a pointer to the next block (similar to a linked list)
Inode table stores start block number, but not number of blocks
Each actual block ends with the number of next block

Advantages
Disadvantages

Indexed Allocation

First block of a file holds the indexes of all other blocks for the file
The inode stores number of the index block, which contains a list of all blocks for the file

Advantages
Disadvantages

File Allocation Table (FAT)

Many Windows installations use the FAT disk format

Simply put, FAT is an indexed allocation method where the inode table is stored in its own part of the disk

Advantages
Disadvantages

New Technology File System (NTFS)

Default disk format for new Windows installations since Windows 3.1 (1993)
Uses a master file table (MFT) but the general principle is the same as FAT
Disk is formatted differently to provide many useful new features

Popular File Systems

Windows:

L2

Files Everywhere

The fundamental concept in Unix is that everything is a file, even things you wouldn't expect like sockets, processes, USB ports, printers
This allows us to use the same system calls and commands to access everything
Presents a clean system call interface to applications and developers

Linux File Systems

Users and programs see a unified view of the file system as a tree-like structure of nested directories and files
This is an abstraction (logical representation) because in reality:

Logical System Tree

The Linux file system tree is a logical structure that could be provided by multiple physical disks, networks, or other devices

Root & Boot

There are two directories that need to be available while the system is booting and the kernel is forking its initial processes

Other parts of the logical file system are mounted in the correct place by the kernel after it has finished loading
You can use the df command to see mount points and physical disks

The EXT4 File System

EXT4 is the most common Linux file system
It can support very large disk and file sizes

EXT4 Block Groups

EXT4 uses the concept of block groups

EXT4 Physical Disk Format

Superblock at start of disk
Group descriptors block
Data bitmap / Inode bitmap / Inode tables for each block group
File storage area split into blocks

Inode Data Structure

Every file (and directory) has an inode associated with it

Directory Data Structure

A file inode does not store the name of the file
Content of each directory is stored as a normal file in a block somewhere on disk

Permissions and other metadata about each directory are stored in the inode that points to that directory data block
Since directories can be nested, some of the inodes listed in the directory block could point to other directory blocks (and so on)
Kernel has to follow a trail of inode numbers and block indexes before it can finally read the actual data blocks for a file

File Data Diagram

![[Pasted image 20250519022243.png]]

Deleting Files

When a file is deleted, its data blocks are not actually removed

Files can be recovered using specialist software

Many operating systems provide secure delete and secure format facilities

Symbolic Links (Hard and Soft)

A file can be given a second filename with the ln command (ln file1 file2)

Or, a soft link can be created to the file ln -s file1 file2

EXT4 Optimisation Features

Standard File Streams

Every Linux system has three standard streams

File Descriptors

Every open file has a file descriptor (a positive integer)